;使用宏方便汇编语言进行交互
;和portio.h里面的inline函数是一样的

PIC_M_CTRL equ 0x20
PIC_M_DATA equ 0x21
PIC_S_CTRL equ 0xA0
PIC_S_DATA equ 0xA1

; %1 : uint16_t port, 
; %2 : uint8_t data
%macro OUTB 2
    push eax
    push edx
    mov al, %2
    mov dx, %1
    out dx, al
    pop edx
    pop eax
%endmacro

; %1 : uint16_t port
%macro INB 1
    push edx
    mov dx, %1
    in al, dx
    pop edx
%endmacro

; %1 : uint16_t port
; %2 : void* addr
; %3 : uint32_t word_cnt
%macro INSW 3
    push edi
    push ecx
    push edx
    mov edi, %2
    mov ecx, %3
    mov dx, %1
    cld
    rep insw
    pop edx
    pop ecx
    pop edi
%endmacro

; %1 : uint16_t port
; %2 : const void* addr
; %3 : uint32_t word_cnt
%macro OUTSW 3
    push esi
    push ecx
    push edx
    mov esi, %2
    mov ecx, %3
    mov dx, %1
    cld
    rep outsw
    push edx
    push ecx
    push esi
%endmacro